<?php

namespace App\Api\Dao;

use App\Models\TongContent;
use App\Models\TongSourceContent;

class ContentDao extends BaseDao
{

    /**
     * 查询构造器
     * @param $data
     * @return \Illuminate\Database\Eloquent\Builder
     */
    function getBuildQuery($data)
    {
        // TODO: Implement getBuildQuery() method.
        $query = TongContent::query();
        if(checkIsHasField($data,'id')){
            $query->where('id',$data['id']);
        }
        if(checkIsHasField($data,'c_id')){
            $query->where('c_id',$data['c_id']);
        }
        $query->orderBy('created_at','desc');

        return $query;
    }

    /**
     * 获取素材列表
     * @param array $data
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public function getContentList(array $data)
    {
        return $this->getBuildQuery($data)->get();
    }

    /**
     * @param array $data
     * @return void
     */
    public function getContentInfo(array $data)
    {
        TongContent::query()->where('id',$data['id'])->increment('look_num');
        return $this->getBuildQuery($data)->first();
    }
}
